/**
 * User class
 */
package com.users;

import java.util.List;

import com.data.documents.UserDocument;

/**
 * The User superclass. It is the parent of all the user classes (Patient,
 * Nurse, Doctor, System Admin). All users have a name an id and a password, as
 * well as a login method.
 * 
 * @version 3.1.4.1.5.9
 * 
 * @author Elizabeth
 * @author Taylor
 */
public class User implements Comparable<User> {

	/** The Constant PATIENT. */
	public static final int ADMIN = 0, DOCTOR = 1, NURSE = 2, PATIENT = 3;

	/** The name. */
	private String name;

	/** The username. */
	private String username;

	/** The user_type. */
	private int user_type;

	/** The suspended. */
	private boolean suspended;
	
	private List<UserDocument> currentDocuments;
	
	/**
	 * Makes a new.
	 * 
	 * @param name
	 *            the name
	 * @param username
	 *            the username
	 * @param user_type
	 *            the user_type
	 * @param suspended
	 *            the suspended
	 */
	public User(String name, String username, int user_type, boolean suspended) {
		this.name = name;
		this.username = username;
		this.user_type = user_type;
		this.suspended = suspended;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *            the new name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the username.
	 * 
	 * @param username
	 *            the new username
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * Gets the username.
	 * 
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * Sets the user_type.
	 * 
	 * @param user_type
	 *            the new user_type
	 */
	public void setUser_type(int user_type) {
		this.user_type = user_type;
	}

	/**
	 * Gets the user_type.
	 * 
	 * @return the user_type
	 */
	public int getUser_type() {
		return user_type;
	}

	/**
	 * Gets the vals as arr.
	 * 
	 * @return the vals as arr
	 */
	public String[] getValsAsArr() {
		final String[] vals = new String[PATIENT];
		vals[0] = name;
		switch (user_type) {
		case ADMIN:
			vals[1] = "ADMIN";
			break;
		case DOCTOR:
			vals[1] = "DOCTOR";
			break;
		case NURSE:
			vals[1] = "NURSE";
			break;
		case PATIENT:
			vals[1] = "PATIENT";
			break;
		default:
			vals[1] = "PATIENT";
			break;
		}
		vals[2] = username;
		return vals;
	}

	/**
	 * Sets it to a string, dammit
	 * 
	 * @return The user as a String
	 */
	@Override
	public String toString() {
		String result = "";
		result += name + ",\n";
		switch (user_type) {
		case ADMIN:
			result += "ADMIN,\n";
			break;
		case DOCTOR:
			result += "DOCTOR,\n";
			break;
		case NURSE:
			result += "NURSE,\n";
			break;
		case PATIENT:
			result += "PATIENT,\n";
			break;
		default:
			break;
		}
		result += username;
		return result;
	}

	/**
	 * Compare two users
	 * 
	 * @param user
	 *            The user to compare to
	 * @throws ClassCastException
	 * @return Comparisonness
	 */
	@Override
	public int compareTo(User user) {
		if (user == null) {
			return 1;
		}
		if (user.user_type != user_type) {
			return user_type - user.user_type;
		}
		if (!user.name.equals(name)) {
			return name.compareTo(user.name);
		}
		return username.compareTo(user.username);
	}

	/**
	 * Check equality of two users
	 * 
	 * @param o
	 *            The object to compare to
	 * @return Equality
	 */
	@Override
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if(super.equals(o)){
			return true;
		}
		if (o instanceof User) {
			final User user = (User) o;
			return user.getUsername().equals(getUsername());
		} else {
			return false;
		}
	}

	/**
	 * Create a hash code
	 * 
	 * @return A hash code of the User
	 */
	@Override
	public int hashCode() {
		return username.hashCode() + name.hashCode();
	}

	/**
	 * Sets the suspended.
	 * 
	 * @param suspended
	 *            the new suspended
	 */
	public void setSuspended(boolean suspended) {
		this.suspended = suspended;
	}

	/**
	 * Checks if is suspended.
	 * 
	 * @return true, if is suspended
	 */
	public boolean isSuspended() {
		return suspended;
	}
	
	public List<UserDocument> getDocuments(){
		return currentDocuments;
	}
	
	public void setDocuments(List<UserDocument> d){
		currentDocuments = d;
	}
}